package main

import (
	"fmt"
	"math/rand"
	"sort"
	"time"
	"unicode"
)
import "strings"

func main() {
	//1
	fmt.Println(titleChange("never gonna give you up"))
	//2
	fmt.Println(startABCandEndXYZ("abc2xyz"))
	//3
	var s []int
	fmt.Println(sortAndSum(s))
	//4
	s1 := []int{1, 2, 3, 4, 5, 6, 7}
	var s2 []int = make([]int, len(s1))
	copy(s2, s1)
	//5
	for _, v := range s1 {
		fmt.Println(isPrime(v))
	}
	//6
	var start string
	var score int
	for {
		fmt.Println("按任意键开始，退出按q")
		fmt.Scanln(&start)
		if start == "q" {
			break
		}
		fmt.Println("输入分数")
		fmt.Scanln(&score)
		if start != "q" {
			switch {
			case score >= 90:
				fmt.Println("A")
			case score >= 80:
				fmt.Println("B")
			case score >= 60:
				fmt.Println("C")
			default:
				fmt.Println("不及格")
			}
		} else {
			break
		}
	}
	//7

	//8
	timeChange("30/06/2022 10-30")
	//9
	var year, month, day int
	fmt.Println("输入年月日")
	fmt.Scanln(&year, &month, &day)
	fmt.Println(dayInYear(year, month, day))
	//10
	countWord("abc2xyz55!@#dd")

}

func titleChange(s string) (result string) {
	return strings.Title(s)
}

func startABCandEndXYZ(s string) (result bool) {
	if len(s) >= 6 && strings.Index(s, "abc") == 0 && strings.Index(s, "xyz") == len(s)-3 {
		return true
	}
	return false
}

func sortAndSum(s []int) (result []int, result2 int) {
	rand.Seed(time.Now().Unix())
	for i := 0; i < 5; i++ {
		cur := rand.Intn(100)
		s = append(s, cur)
		result2 += cur
	}
	sort.Ints(s)
	result = s
	return
}

func isPrime(num int) (result bool) {
	for i := 2; i < num; i++ {
		if num%i == 0 {
			return false
		}
	}
	return true
}

func timeChange(s string) {
	day := s[0:2]
	month := s[3:5]
	year := s[6:10]
	hour := s[11:13]
	minute := s[14:16]
	fmt.Printf("%s-%s-%s %s:%s\n", year, month, day, hour, minute)
}

func dayInYear(year int, month int, day int) (result int) {
	days := [12]int{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
	if year%4 == 0 && year%100 != 0 || year%400 == 0 {
		days[1] = 29
	}
	for i := 0; i < month-1; i++ {
		result += days[i]
	}
	result += day
	return
}
func countWord(s string) {
	letter := 0
	digit := 0
	orther := 0
	for i := 0; i < len(s); i++ {
		if unicode.IsLetter(rune(s[i])) {
			letter++
		} else if unicode.IsDigit(rune(s[i])) {
			digit++
		}
		orther = len(s) - letter - digit

	}
	fmt.Printf("the number of letter is:%d,"+
		"the number of digit is:%d,"+
		"the number of orther is:%d", letter, digit, orther)
}
